import Vue from 'vue'

import VueRouter from 'vue-router'
import 'element-ui/lib/theme-chalk/index.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
Vue.use(VueRouter)
import login from '@/views/login/login.vue'
import layout from '../views/layout/layout.vue'
import data from '../views/layout/data/data.vue'
import userlist from '../views/layout/userlist/userlist.vue'
import business from '../views/layout/business/business.vue'
import quesition from '../views/layout/quesition/quersition.vue'
import subject from '../views/layout/subject/subject.vue'
var router = new VueRouter({
    routes: [
        { path: '/', redirect: '/login' },
        {
            path: '/login',
            component: login
        },
        {
            path: '/layout', component: layout,
            children: [
                {
                    path: '/layout/data', component: data
                    , meta: {
                        title: '数据概述'
                    }
                }, {
                    path: '/layout/userlist', component: userlist
                    , meta: {
                        title: '用户列表'
                    }
                }, {
                    path: '/layout/quesition', component: quesition, meta: {
                        title: '题库列表'
                    }
                }, {
                    path: '/layout/business', component: business
                    , meta: {
                        title: '企业列表'
                    }
                }, {
                    path: '/layout/subject', component: subject
                    , meta: {
                        title: '学科列表'
                    }
                }
            ]
        }
    ]
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
router.beforeEach((to, from, next) => {
    console.log(to)
    console.log(from)
    NProgress.start(),
        next()
})
router.afterEach((to, from) => {
    console.log(to)
    console.log(from)
    document.title = to.meta.title
    NProgress.done()
})
export default router